#!/bin/bash

function usage () {
	echo "usage: $0 [file]"
	echo "Count characters and print LinuxPratique price for them."
	echo "Read from stdin if no file is given."
	exit
}

if [ $# -gt 2 ]; then
	usage
fi

if [ $# -eq 1 ]; then
	if ! [ -r "$1" ]; then
		echo "$1 not found."
		usage
	fi

	cat $1 | $0
	exit
fi

read a
count=0
while [ $? -eq 0 ]; do
	count=$(($count+$(echo $a | sed 's/ //' | wc -m)))
	read a
done

echo "$count characters."
echo "$(echo $count *45/1500|bc) Euros."
